#include "type.h"

#define MAP_INVALID 1
#define MAP_REAL 2
#define MAP_GHOST 3
#define MAP_CLEAN 4
#define PAGE_CLEAN 5

#define CACHE_INVALID 0
#define CACHE_VALID 1

#define MAP_ENTRIES_PER_PAGE 512

#define CLEAN_PAGE_MAPDIR_NUM_PER_PAGE 512

#define MIN_SEQ_REQ_NUM 8


//translation pagemap 
struct vftl_pm_entry{
	_u32 free : 1 ;
	_u32 ppn : 31 ;
	int cache_status;
	int cache_age;
	int map_status;
	int map_age;
	int update;
	//int local;//0 flash,1 cache; use for clean_arr/clean page
};

//GTD table
struct trans_page_mapdir{
	_u32 free;
	_u32 ppn;
	int update;
};

/*struct clean_page_mapdir{
	int lpn;
    _u32 free;
	_u32 ppn;
	int update;
    int local;
};

struct clean_trans_page_info{
	int lpn;
	_u32 free;
	_u32 ppn;
	int  updata;		
};*/

int CACHE_NUM_ENTRIES;

sect_t vftl_pagemap_num;// all page of flash
struct vftl_pm_entry *vftl_pagemap;
struct trans_page_mapdir * trans_page_dir;
//struct clean_page_mapdir * clean_page_dir;
//struct clean_trans_page_info * clean_page_info;

_u32 curr_transpage_blk_no;  //translation page
_u16 curr_transpage_page_no;

_u32 curr_datapage_blk_no;  //hot data
_u16 curr_datepage_page_no;

_u32 curr_cold_data_blk_no; //cold data
_u16 curr_cold_date_page_no;

//_u32 curr_clean_transpage_blk_no; //clean page
//_u16 curr_clean_transpage_page_no;

int evict_clean_pos;// hit clean_arr[] pos

int curr_trans_maptable_no;//spcmt 's lpn?
int curr_trans_mpatable_update_mark;

//int curr_clean_maptable_no;//cpcmt 's ppn?

//ftl read/write opreation

int vftl_init(blk_t blk_num, blk_t extra_num);
size_t vftl_write(sect_t lsn, sect_t size, int mapdir_flag);
size_t vftl_read(sect_t lsn, sect_t size, int mapdir_flag);
struct ftl_operation * vftl_setup();
void vftl_end();
void vftl_pagemap_reset();


void trans_page_maptable_write(sect_t lsn, sect_t size, int mapdir_flag);
void trans_page_maptable_read(sect_t lsn, sect_t size, int mapdir_flag);
//void clean_page_maptable_read(sect_t lsn, sect_t size, int mapdir_flag);
//void clean_page_maptable_write(sect_t lsn, sect_t size, int mapdir_flag);


//GC operation
void vftl_gc_cost_benefit();
void vftl_gc_get_free_blk(int mapdir_flag);

void vftl_gc_run();










